<template>
  <div class="box-wrap">
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field
          v-model="username"
          type="digit"
          name="帐号"
          label="帐号"
          placeholder="帐号"
          :rules="[{ required: true, message: '请填写帐号' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
      </van-cell-group>
      <div style="margin: 16px;">
        <van-button round block type="primary" native-type="submit">登 陆</van-button>
      </div>
    </van-form>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { storeToRefs } from 'pinia'
import { userStore } from '@/stores/mqttStore'
import { useRouter } from 'vue-router'

const router = useRouter()
const username = ref('');
const password = ref('');
const onSubmit = (values) => {
  const { uid } = storeToRefs(userStore())
  uid.value = username.value
  router.push({
    path: '/'
  })
};
</script>

<style scoped>
.box-wrap{
  width: 100vw;
  height: 100vh;
  background-color: #f5f6f9;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>